/*
 * Videoclient.h
 *
 *  Created on: 2010-03-28
 *      Author: kamil
 */

#ifndef VIDEOCLIENT_H_
#define VIDEOCLIENT_H_

#include <iostream>
#include <sstream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <vector>
#include <map>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/map.hpp>

#include <log4cxx/logger.h>

#include "Videodata.h"

class Videoclient {
public:
	Videoclient(boost::asio::io_service & io_service);
	~Videoclient();

	void connect(std::string  serverIP, int port);

	bool areNewDataPresent();

	void consumeVideodata(std::map<std::string, Videodata> * vd, double * simTimeStamp);

private:
	void prepareRead();

	void handleHeader(const boost::system::error_code & error, std::size_t);
	void handleData(const boost::system::error_code & error, std::size_t);

	boost::asio::io_service & io_service;
	boost::asio::ip::udp::socket socket;

	static const int header_size = 16;
	char header[header_size];
	std::size_t data_size;
	std::vector<char> data;
	std::string * archiveData;

	static log4cxx::LoggerPtr logger;
};

#endif /* VIDEOCLIENT_H_ */
